package com.newland.starpos.project.http;

import org.springframework.http.HttpStatus;

import com.fasterxml.jackson.annotation.JsonInclude;

import lombok.Getter;

@Getter
public class ResponseModel<T> {

	private int code;

	private Object message;

	@JsonInclude(value = JsonInclude.Include.NON_NULL)
	private T body;

	public static <T> ResponseModel<T> ok() {
		return build(HttpStatus.OK, HttpStatus.OK.getReasonPhrase());
	}

	public static <T> ResponseModel<T> ok(T body) {
		ResponseModel<T> response = build(HttpStatus.OK, HttpStatus.OK.getReasonPhrase());
		response.body = body;
		return response;
	}

	public static <T> ResponseModel<T> error(HttpStatus httpCode, Object message) {
		return build(httpCode, message);
	}

	public static <T> ResponseModel<T> build(HttpStatus httpCode, Object message) {
		ResponseModel<T> response = new ResponseModel<>();
		response.code = httpCode.value();
		response.message = message;
		return response;
	}

}
